//
//  AppDelegate.m
//  FilmParadise
//
//  Created by YangYujie on 15/7/12.
//  Copyright (c) 2015年 DLYgroup. All rights reserved.
//

#import "AppDelegate.h"
#import "FPBaseTabBarController.h"
#import "UMSocial.h"
#import <MediaPlayer/MediaPlayer.h>
#import "BMapKit.h"
#import "UMSocialWechatHandler.h"
#import "UMSocialQQHandler.h"
@interface AppDelegate ()<BMKGeneralDelegate>
@property (nonatomic , strong)UIView *btnView;
@property (nonatomic , strong)MPMoviePlayerViewController *movieVC;
@property (nonatomic , strong)BMKMapManager *mapManager;
@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    //注册通知判断rotate
     [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(statuechange:) name:@"allowRotate" object:nil];
    [self playMovie];
    [self.window makeKeyAndVisible];
    [self baiduMap];
    return YES;
}
- (void)statuechange:(NSNotification *)aNotification
{
    AppDelegate *applegatate = aNotification.object;
    self.isAllowedRotate = applegatate.isAllowedRotate;
}
// 要使用百度地图要先启动BaiduMapManager
- (void)baiduMap
{
    _mapManager = [[BMKMapManager alloc] init];
    BOOL ret = [_mapManager start:@"eq8abgG6POGuo94CmFKf6w7S" generalDelegate:self];
    if (!ret) {
        NSLog(@"manager start failde!");
    }
}

- (void)startMain
{
    [UMSocialData setAppKey:@"55acadd6e0f55a7e410046b0"];
     [UMSocialQQHandler setQQWithAppId:@"100424468" appKey:@"55acadd6e0f55a7e410046b0" url:@"http://www.mtime.com"];
    [UMSocialWechatHandler setWXAppId:@"wx9865e6f51d03a143" appSecret:@"fd58e8f16c0dfb6023be1e977a168233" url:@"http://www.mtime.com/"];
    [UMSocialConfig hiddenNotInstallPlatforms:@[UMShareToQQ,UMShareToQzone,UMShareToWechatSession,UMShareToWechatTimeline]];
    FPBaseTabBarController *baseTabBarC = [[FPBaseTabBarController alloc]init];
    [_movieVC.view removeFromSuperview];
    [_btnView removeFromSuperview];
    [self.window setRootViewController:baseTabBarC];

}
- (void)playMovie
{
    NSString *strPath =[ [NSBundle mainBundle] pathForResource:@"testMM" ofType:@"mp4"];
    NSURL *url = [NSURL fileURLWithPath:strPath];

    NSLog(@"%@",url);
    self.movieVC  = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
    _movieVC.moviePlayer.controlStyle = MPMovieControlStyleNone;
    _movieVC.moviePlayer.repeatMode = MPMovieRepeatModeOne;
    [_movieVC.view setFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    [self.window addSubview:_movieVC.view];
    [self setView];
    [_movieVC.moviePlayer play];
}

- (void)setView
{
    self.btnView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    _btnView.backgroundColor = [UIColor clearColor];
    UIButton *goInToBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    goInToBtn.backgroundColor = [UIColor colorWithRed:0.500 green:0.486 blue:0.471 alpha:0.800];
    goInToBtn.frame = CGRectMake(kImageW(135), kImageH(520), kImageW(120), kImageH(30));
    [goInToBtn setTitle:@"进入电影世界" forState:UIControlStateNormal];
    goInToBtn.layer.masksToBounds = YES;
    goInToBtn.layer.cornerRadius  = 10;
    [goInToBtn setTitleColor:[UIColor colorWithRed:0.334 green:0.811 blue:0.888 alpha:1.000] forState:UIControlStateNormal];
    [goInToBtn addTarget:self action:@selector(goMain) forControlEvents:UIControlEventTouchUpInside];
    [_btnView addSubview:goInToBtn];
    [self.window addSubview:_btnView];
}
- (void)goMain
{
     [self startMain];
}
- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    
    
    if (self.isAllowedRotate == NO)
    {
        return UIInterfaceOrientationMaskPortrait;
    }
    return UIInterfaceOrientationMaskAll;
}



- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
